package app.fugema.shop.main.invoice.view;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;

import com.base.common.app.LoginUtils;
import com.base.common.netBeanPackage.LiveDataWrapper;
import com.base.common.utils.DialogUtils;
import com.base.common.utils.LogUtil;
import com.base.common.utils.UIUtils;
import com.base.common.view.base.BaseTitleActivity;
import com.base.common.view.base.OnGetDataListener;
import com.base.common.view.widget.statelayout.StateLayout;
import com.base.common.viewmodel.BaseViewObserver;
import app.fugema.shop.R;
import app.fugema.shop.databinding.ActivityRecyclerviewListBinding;
import app.fugema.shop.main.center.model.TotalIntegralBean;
import app.fugema.shop.main.invoice.adapter.IntegralListAdapter;
import app.fugema.shop.main.center.model.PointResultBean;
import app.fugema.shop.main.invoice.vm.InvoiceVM;

public class IntegralRecordActivity extends BaseTitleActivity<ActivityRecyclerviewListBinding, InvoiceVM> implements OnGetDataListener {
    //我的积分页面

    private String userKy = "";

    private int integral;

    public static void start(Context context ,int integral )
    {
        Intent intent = new Intent(context, IntegralRecordActivity.class);
        intent.putExtra("integral",integral);
        context.startActivity(intent);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recyclerview_list);
    }

    private IntegralListAdapter adapter;

    @Override
    protected int getStatusBarColor()
    {
        return R.color.redColor;
    }
    @Override
    protected void initView()
    {
        super.initView();
        setCloseImg(R.mipmap.ic_back_white);
        setTitle("我的积分",R.color.white);

        adapter = new IntegralListAdapter();

        binding.rvRecyclerView.setAdapter(adapter);

        viewUtils.setRefreshStateLayout(binding.rvRecyclerView, this, this);

        viewUtils.getStateLayout().setTipText(StateLayout.EMPTY, "暂无问积分记录");
    }

    @Override
    protected void initData(Intent intent)
    {
        super.initData(intent);
        userKy = LoginUtils.getToken();

        integral = intent.getIntExtra("integral",0);
        LogUtil.e("integral = " + integral);
        TotalIntegralBean  total = new TotalIntegralBean();
        total.setTotal( integral );
        adapter.addHeaderView( total ,0 );
        onGetData(1);
    }

    @Override
    public void onGetData(int pn)
    {
        //查积分 列表
        viewModel.pointRecord(userKy ,pn).observe(this, new BaseViewObserver<LiveDataWrapper<PointResultBean>>(viewUtils.getStateLayout()) {
            @Override
            protected void onSuccess(LiveDataWrapper<PointResultBean> data)
            {

                viewUtils.setDataListRefreshLayout(adapter, pn, 15, data.data.getData());
            }

            @Override
            public boolean isEmptyData(LiveDataWrapper<PointResultBean> data)
            {
                return pn == 1 && UIUtils.isEmpty(data.data.getData());
            }

            @Override
            public boolean isRefreshLayoutData()
            {
                return true;
            }
        });
    }

    private void showDialog()
    {
        DialogUtils.showSimpleDialog(getActivity(), false, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        }, "确定删除这条问诊吗？");
    }
}
